package com.chuisha.stu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chuisha.stu.service.OrderService;
import com.chuisha.stu.service.dao.OrderDao;
import com.chuisha.stu.service.dao.OrderEntity;
import com.chuisha.stu.service.vo.OrderVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;

    public OrderVO selectByOrderNo(String orderNo) {
        OrderEntity entity = new OrderEntity();
        entity.setOrderNo(orderNo);
        entity = orderDao.selectOne(new QueryWrapper<>(entity));
        if (entity == null) {
            return null;
        }
        OrderVO orderVO = new OrderVO();
        BeanUtils.copyProperties(entity, orderVO);
        return orderVO;
    }

    public OrderVO updateOrder(OrderVO orderVO) {
        OrderEntity entity = new OrderEntity();
        BeanUtils.copyProperties(orderVO, entity);
        orderDao.updateById(entity);
        return new OrderVO();
    }

    public OrderVO insertOrder(OrderVO orderVO) {

        OrderEntity entity = new OrderEntity();
        BeanUtils.copyProperties(orderVO, entity);
        orderDao.insert(entity);
        orderVO.setId(entity.getId());
        return orderVO;
    }

    public int deleteOrder(String orderNo) {
        OrderEntity entity = new OrderEntity();
        entity.setOrderNo(orderNo);
        return orderDao.delete(new QueryWrapper<>(entity));
    }
}
